<?php
namespace Admin\Model;
use Think\Model;

class VideoBookModel extends Model{
    protected $connection = 'DB_CONFIG2';
//     protected $tablePrefix = 'shop_';

	/**
	 * 根据条件，返回订单总数
	 * @param string $where
	 * @return number|NULL
	 */
	public function getOrdersCount($where=null){
		$orderNum = $this->alias('vb')->where($where)
		->join(C('DB_PREFIX').'video_book_info as vbi ON vb.ordersn = vbi.ordersn')
		->select();
		if ($orderNum) {
			$orderNum = count($orderNum);
			return $orderNum;
		}else{
			return null;
		}
	}

	/**
	 * 获取订单列表，并分页，返回订单列表
	 * @param unknown $page
	 * @param string $where
	 * @return unknown|NULL
	 */
	public function getOrderList($page,$where=null,$p=null,$type="select"){
	    if($type=="select"){
	        $orderList = $this->field('vb.id as order_id,vb.create_time as o_create_time,vb.*,vbi.*')->
	        alias('as vb')->
	        join(C('DB_PREFIX').'video_book_info as vbi ON vb.ordersn = vbi.ordersn')->
	        where($where)->order('vb.id desc')->page($p)->select();
	    }
	    else if($type=="find"){
	        $orderList = $this->field('vb.id as order_id,vb.create_time as o_create_time,vb.*,vbi.*')->alias('as vb')->
	        join(C('DB_PREFIX').'video_book_info as vbi ON vb.ordersn = vbi.ordersn')->
	        where($where)->order('vb.id asc')->find();
	    }

		if ($orderList) {
			return $orderList;
		}else{
			return null;
		}
	}

}

?>
